<?php
/**
 * class ExcelSimpleExport
 * 简易导出excel方法
 *
 * @author wangsl <wangsl@mingyuanyun.com>
 */

namespace common\support;

class ExcelSimpleExport
{
    public static function get_csv_handler($filename) {
        header('Content-Encoding: UTF-8');
        header('Content-Type: text/csv;charset=UTF-8');
        header("Content-Disposition: attachment;filename = $filename.csv");
        header('Cache-Control: max-age=0');

        // 告诉excel文件编码为utf8,然后让excel自己用合适的编码打开
        echo "\xEF\xBB\xBF"; // UTF-8 BOM

        // 直接输出到浏览器
        $fp = fopen('php://output', 'a');

        return $fp;
    }

    public static function output_csv_head(&$fp, $head) {
        fputcsv($fp, $head);
        fclose($fp);
    }
}